//! Leases are a mechanism for detecting client liveness. The cluster grants leases with a time-to-live. A lease expires if the etcd cluster does not receive a keepAlive within a given TTL period.
//!
//! # Examples
//!
//! Grant lease and keep lease alive

mod grant;
mod keep_alive;
mod revoke;
mod time_to_live;

pub use grant::{LeaseGrantRequest, LeaseGrantResponse};
pub use keep_alive::{LeaseKeepAliveRequest, LeaseKeepAliveResponse};
pub use revoke::{LeaseRevokeRequest, LeaseRevokeResponse};
pub use time_to_live::{LeaseTimeToLiveRequest, LeaseTimeToLiveResponse};

use async_trait::async_trait;
use crate::Result;

pub type LeaseId = i64;

#[async_trait]
pub trait LeaseOp {
    async fn grant_lease<R>(&self, req: R) -> Result<LeaseGrantResponse>
    where
        R: Into<LeaseGrantRequest> + Send;

    async fn revoke<R>(&self, req: R) -> Result<LeaseRevokeResponse>
    where
        R: Into<LeaseRevokeRequest> + Send;

    async fn keep_alive(&self, lease_id: LeaseId) -> Result<Option<LeaseKeepAliveResponse>>;

    async fn time_to_live<R>(&self, req: R) -> Result<LeaseTimeToLiveResponse>
    where
        R: Into<LeaseTimeToLiveRequest> + Send;
}
